#ifndef __COMMON_H__
#define __COMMON_H__

#include "STC12C5410AD.h"

#ifdef SDCC
	#define bool __bit
	#define interrupt __interrupt
	#define code __code
	#define xdata __xdata
	#pragma disable_warning 126
#else
	#define bool bit
	#include <stdlib.h>
	#include <string.h>
#endif
#define uchar unsigned char
#define uint unsigned int
#define false 0
#define true 1

#define OSCFREQ 24000//24000kHz
#define XDATA_SIZE 256//stc12c5406ad xdata size

//following definition used to reduce code size
//#define DEVELOP_PHASE //reduce code size by remove validation codes in development phase
#define MARCO_TO_FUNCTION	//reduce code size by replace code macros to functions
#define RECONFIG_BT	//modify bt module's name/class/bps...

//define feature to use
#define USE_DISP
#ifdef USE_DISP
//	#define DISP_NUMBER_ONLY		//only digital numbers can be displayed
//	#define DISP_NO_RACE_HORSE	//all race horse display functions will be ignored
//	#define DISP_SIMPLIFY_ERROR_CODE	//error code will be simplified to number of dots instead of error code number
#endif

//#define USE_PCA	//motor control
//#define USE_SFB	//speedfeedback control
#define USE_NVS	//non-volatile storage control

//mem feature to use
#define USE_HEAP 0
#ifdef SDCC
#define HEAP_SIZE XDATA_SIZE
#else
#define HEAP_SIZE XDATA_SIZE-8
#endif
#define SDM_HEAP_SIZE 32
#define DISP_STRING_SIZE 32

//timer define
#define TH(x) _TH(x)
#define _TH(x) TH##x

#define TL(x) _TL(x)
#define _TL(x) TL##x

#define ET(x) _ET(x)
#define _ET(x) ET##x

#define TR(x) _TR(x)
#define _TR(x) TR##x

#define PT(x) _PT(x)
#define _PT(x) PT##x

#define TMOD(x,mode) \
	if(x==0) \
 		TMOD|=mode; \
	else \
		TMOD|=(mode<<4); \

#define Tx12(x,a) \
	if(a==false) \
		AUXR&=(~(0x80>>x)); \
	else \
		AUXR|=(0x80>>x); \


//external interrupt define
#define EX(x) _EX(x)
#define _EX(x) EX##x

#define IT(x) _IT(x)
#define _IT(x) IT##x


//PCA
#define PCAPORT(x) _PCAPORT(x)
#define _PCAPORT(x) CEX##x

#define CCAPM(x) _CCAPM(x)
#define _CCAPM(x) CCAPM##x

#define CCAPL(x) _CCAPL(x)
#define _CCAPL(x) CCAP##x##L

#define CCAPH(x) _CCAPH(x)
#define _CCAPH(x) CCAP##x##H

#define CCF(x) _CCF(x)
#define _CCF(x) CCF##x


#endif //__COMMON_H__
